package com.cn.sqlSession;

import com.cn.config.XmlConfigBuilder;
import com.cn.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * sqlsessionfactory 创建工厂
 */
public class SqlSessionFactoryBuilder {

    // 生产 sqlsession
    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {
        // 解析配置文件
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        // 创建SqlSessionFactory对象
        SqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
